package com.shun.upms.biz.impl;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.util.StrUtil;
import com.shun.upms.service.ISysAdminMenuService;
import com.shun.upms.service.ISysAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private ISysAdminMenuService menuService;

    @Autowired
    private ISysAdminRoleService roleService;

    /**
     * 获取权限列表
     * @param loginId
     * @param s
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String s) {
        boolean flag = StrUtil.isEmptyIfStr(loginId);
        return flag ? null : menuService.getMenuCodeByUser(loginId.toString());
    }

    /**
     * 获取角色列表
     * @param loginId
     * @param s
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String s) {
        boolean flag = StrUtil.isEmptyIfStr(loginId);
        return flag ? null : roleService.getRolesByUser(loginId.toString());
    }
}
